#include "../test_type.h"
#include "./server/Server.h"
#include "./server/Session.h"
#include "./server/ThreadServer.h"
#include <memory>
#include <vector>
#include <thread>

#ifdef TEST_ECHO_SERVER_THREAD_POOL

using namespace std;
using namespace echo_service;

int main(int argc, char** argv)
{
	LibTools::ShareApi::PrintDumpInfo(true);
	LOG_SET_LEVEL(LibTools::LOG_WARNING);

	shared_ptr<ThreadService> server(new ThreadService());
	CTcpIoSocket sock;

	if (argc == 3)
		server->Start(argv[1], atoi(argv[2]));
	else
		server->Start();

	cout << "service start..." << endl;

	vector<thread> threads;
	for (size_t i = 0; i < server->_tcps.size(); i++)
	{
		threads.push_back(thread([i, server]()->bool {return server->_tcps[i]->Run(); }));
	}

	for (int i = 0; i < threads.size(); i++)
	{
		threads[i].join();
	}

	cout << "service stop..." << endl;

	return 0;
}

#endif // TEST_ECHO_SERVER_THREAD_POOL
